﻿using de.wolfmarco.pas.Client.MVVM;
using de.wolfmarco.pas.Shared.Interfaces;
using de.wolfmarco.pas.Shared.MVVM;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;
using System.Windows;

namespace de.wolfmarco.pas.Client
{
    public class ClientBootstrapper : UnityBootstrapper
    {
        #region SHELL

        protected override DependencyObject CreateShell()
        {

            TransientLifetimeManager transientLifetimeManager = new TransientLifetimeManager();

            ShellViewModel viewModel = Container.Resolve<ShellViewModel>();

            Container.RegisterInstance<ModuleViewModel>("Shell", viewModel);

            InjectionMember[] injectionMember = new InjectionMember[]
            {
                new InjectionProperty( "DataContext", viewModel )
            };

            Container.RegisterType(typeof(object), typeof(ShellView), transientLifetimeManager, injectionMember);

            return Container.Resolve<ShellView>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();
            App.Current.MainWindow = (Window)Shell;
            App.Current.MainWindow.Show();
        }

        #endregion SHELL

        #region MODULES

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new DynamicDirectoryModuleCatalog();
        }

        #endregion MODULES
    }
}
